<?php

	if ( isset($_GET['subButton']) ) {
		
		if ( !empty($_GET['txtstudno']) || !empty($_GET['txtfirst']) || !empty($_GET['txtlast']) || !empty($_GET['txtsubject']) || !empty($_GET['txtsemester']) || !empty($_GET['txtsection']) ) {
			$listCountStudentInformation = $STUD->arraySearchStudentInformationCount($activeYear, $_GET); //COUNT
		
			if( $listCountStudentInformation > 0 ) {
				$countNum			= 20;
				$pagenum 			= $_GET["page_no"];
				$page_rows 			= $PAGINATION->numPerRow($countNum);
				$last 				= $PAGINATION->lastCeilPerRow($listCountStudentInformation, $page_rows);
				$pagenum 			= $PAGINATION->pageNumRow($pagenum, $last); 
				$pageLimit 			= $PAGINATION->limitRow($pagenum, $page_rows);
				
				$arrBut				= array('first' 	=> '<img src="' . DIR_IMAGES . 'pagination_first.png" title="First" border="0" />',
											'previous' 	=> '<img src="' . DIR_IMAGES . 'pagination_prev.png" title="Previous" border="0" />',
											'next' 		=> '<img src="' . DIR_IMAGES . 'pagination_next.png" title="Next" border="0" />',
											'last' 		=> '<img src="' . DIR_IMAGES . 'pagination_last.png" title="Last" border="0" />',);
				$classCSS			= array('button' 	=> 'pagination-button', 'label' 	=> 'pagination-label');
				$urlGet				= array('hash' => hashRandom($_GET), 'page' => $_GET['page'], 'txtstudno' 	=> $_GET['txtstudno'], 'txtfirst' 	=> $_GET['txtfirst'], 'txtlast' 	=> $_GET['txtlast'], 'txtsemester' 	=> $_GET['txtsemester'], 'txtsection' 	=> $_GET['txtsection'], 'subButton' => $_GET['subButton']);
				
				if( $listCountStudentInformation > $countNum ) {
					$pagination 	= $PAGINATION->pagination($arrBut, $pagenum, $last, $classCSS, $urlGet);
				}
			}
				
			$studList = $STUD->arraySearchStudentInformation($activeYear, $_GET, $pageLimit);
			
			$name = 'No Record Found.';
		}
		
	}
	# LSITING
	if ( !empty($studList) ) {
		unset($_GET['subButton']);
		unset($_GET['page']);
		
		$printButton = '&nbsp;&nbsp;<input type="button" class="search-input green" value="Print Preview"  onclick="popupRequest(\'show\', \'PrintStudentSearch\', \'Student Search\', \'480\', \'600\', \'' . 'search&' . http_build_query($_GET) . '\');"/>';
		
		if ( !empty($_GET['txtsubject']) ) {
			$printButton .= '&nbsp;<input type="button" class="search-input green" value="Grade Sheets"  onclick="popupRequest(\'show\', \'PrintStudentGradesSearch\', \'Student Search\', \'480\', \'700\', \'' . 'search&' . http_build_query($_GET) . '\');"/>';
		}
		
		$headerTable = '<tr class="tr-header">
							<td width="120" class="td-label">&nbsp;</td>
							<td width="15" class="td-label">&nbsp;</td>
							<td width="75" class="td-label">Student #</td>
							<td width="220" class="td-label">Name</td>
							<td width="100" class="td-label">Section</td>
							<td width="60" class="td-label">Course</td>
							<td width="120" class="td-label"></td>
						</tr>';
		
		$TEMP->set_block('handle',  'students', 'studentsRow');
		$bgcolor 	= LOOPING_F0F;
		$numCount 	= 1;
		
		if ( intval($_GET['page_no']) > 1 ) {
			$countNumSub = intval($_GET['page_no']);
			$numCount += intval($_GET['page_no'] - 1) * $countNum;
		}
			
		foreach($studList as $studListField => $studListValue) {
			
			$studID 		= $studListValue['stud_idPK'];
			$courseID 		= $studListValue['course_idFK'];
			
			$semActiveFreshmen	= $STUD->getSemesterEnrollmentActive($studID);
			$currentSemester	= $DSC->getSemesterLabel($semActiveFreshmen['sem_linker_idFK']);
			$takeSectionDesc	= $STUD->getStudSectionDesc($studID, $courseID, $semActiveFreshmen['sem_linker_idFK']);
			
			$imgEnrollPayment = $imgEnroll . $imgPayment;
			
			if ($takeSectionDesc['section_desc'] == '') {
				$sectionDesc = '------------';
				$sectionBut = '&nbsp;<img src="' . DIR_IMAGES . 'icon/section_d.png" border="0" title="Edit Section"/>';
			}
			else {
				$sectionDesc = '<span onmouseover="keyDown()" onmouseout="keyUp()" class="blue-link" onclick="popupRequest(\'show\', \'SchedulePerSection\', \'' .  $studListValue['course_desc'] . ' :: '. $takeSectionDesc['section_desc'] .'\', \'500\', \'785\', \'' . $studID . '&cid=' . $courseID . '&sid=' . $takeSectionDesc['section_idPK'] . '&lnk=true\');">' . $takeSectionDesc['section_desc'] . '</span>';
				$sectionBut = '&nbsp;<img src="' . DIR_IMAGES . 'icon/section.png" border="0" title="Edit Section" onclick="popupRequest(\'show\', \'EditStudentSection\', \'Change Student Section\', \'200\', \'500\', \'' . $studListValue['stud_idPK'] . '&slid=' . $semActiveFreshmen['sem_linker_idFK'] .'\');"/>';
			}
			
			$edButton = '<div class="icon-button">
							&nbsp;<img src="' . DIR_IMAGES . 'icon/pencil.png" border="0" title="Edit Profile" onclick="popupRequest(\'show\', \'AdminStudentChangePassword\', \'' . $studListValue['first_name'] . ' ' . $studListValue['middle_name'] . ' ' . $studListValue['last_name'] . '\', \'200\', \'500\', \'' . $studListValue['stud_idPK'] . '\');"/>
							&nbsp;<img src="' . DIR_IMAGES . 'icon/profile.png" border="0" title="View Profile" onclick="popupRequest(\'show\', \'StudentProfile\', \'Student Profile\', \'330\', \'500\', \'' . $studListValue['stud_idPK'] . '\');"/>
							' .$sectionBut . '
							&nbsp;<img src="' . DIR_IMAGES . 'icon/grades.png" onclick="popupRequest(\'show\', \'StudentCurrentSubjectTaken\', \'' . $studListValue['first_name'] . ' ' . $studListValue['last_name'] . '\', \'250\', \'500\', \'' . $studID . '&cid=' . $courseID . '&slid=' . $semActiveFreshmen['sem_linker_idFK'] . '\');" border="0" title="View Profile" onclick="popupRequest(\'show\', \'StudentProfile\', \'Student Profile\', \'330\', \'500\', \'' . $studListValue['stud_idPK'] . '\');"/>
							</div>';

			$TEMP->set_var(array('stud_id' 		=> $studListValue['stud_idPK'],
								 'stud_no' 		=> $studListValue['stud_no'],
								 'name' 		=> $studListValue['last_name'] . ', ' . $studListValue['first_name'] . ' ' . $studListValue['middle_name'],
								 'course_code'	=> '<span class="blue-link" title="' . $studListValue['course_desc'] . '" onclick="popupRequest(\'show\', \'SubjectPrintPreview\', \'' . $studListValue['course_desc'] . ' (' . $studListValue['course_code'] . ')\', \'500\', \'1000\', \'' . $studListValue['course_idFK'] . '\');">' . $studListValue['course_code'] . '</span>' ,
								 'if_enroll'	=> $ifPaymentFull,
								 'section' 		=> $sectionDesc,
								 'is_deleted' 	=> ($studListValue['is_deleted'] == 'N') ? 'enabled' : 'disabled',
								 'checklist'	=> '<span class="blue-link" onclick="popupRequest(\'show\', \'EvaluationChecklist\', \'' .  $studListValue['first_name'] . ' ' . $studListValue['last_name'] . ' :: '. $studListValue['course_desc'] . ' (' . $studListValue['course_code'] . ')\', \'550\', \'710\', \'' . $studID . '&cid=' . $courseID . '\');">CHECKLIST SHEET</span>',
								 'numbering'	=> $numCount.'.',
								 'bgcolor'		=> $bgcolor,
								 'ed_button'	=> $edButton
								));
								
			$TEMP->parse('studentsRow', 'students', true);
			$bgcolor = ($bgcolor == LOOPING_F0F) ? LOOPING_FFF : LOOPING_F0F;
			$numCount++;
		}
	}
	else {
		$TEMP->set_var(array('stud_id' 		=> '',
							 'stud_no' 		=> '',
							 'name' 		=> $name,
							 'course_code'	=> '',
							 'if_enroll'	=> '',
							 'section' 		=> '',
							 'semester' 	=> '',
							 'checklist'	=> '',
							 'is_deleted' 	=> '',
							 'numbering'	=> '',
							 'bgcolor'		=> '',
							 'ed_button'	=> '',
							 'header_table'	=> '',
							));
	}
	
	
	$selectSemesterList = $DSC->getListSemestersDefault();
	$selectSemesterHTML = '<select name="txtsemester" id="txtsemester" class="select-auto-input"><option value=""></option>';
		foreach($selectSemesterList as $semesterListVal) {
			$semesterHTML = ( $_GET['txtsemester'] == $semesterListVal['sem_idPK'] ) ? 'selected' : '';
			$selectSemesterHTML .= '<option value="' . $semesterListVal['sem_idPK'] . '" ' . $semesterHTML . '>' . $semesterListVal['sem_desc'] . '</option>';
		}
	$selectSemesterHTML .= '</select>';
	
	
	$selectSectionList = $DSC->getListSection();
	$selectSectionHTML = '<select name="txtsection" id="txtsection" class="select-auto-input"><option value=""></option>';
		if ( !empty($selectSectionList) ) {
			foreach($selectSectionList as $sectionListVal) {
				$sectionHTML = ( $_GET['txtsection'] == $sectionListVal['section_idPK'] ) ? 'selected' : '';
				$selectSectionHTML .= '<option value="' . $sectionListVal['section_idPK'] . '" ' . $sectionHTML . '>' . $sectionListVal['section_desc'] . '</option>';
			}
		}
	$selectSectionHTML .= '</select>';
	
	
	$selectSubjectCourse = $DSC->getSubjectCourse();
	$selectSubjectnHTML = '<select name="txtsubject" id="txtsubject" class="select-auto-input"><option value=""></option>';
		if ( !empty($selectSubjectCourse) ) {
			foreach($selectSubjectCourse as $subjectCourseField => $selectSubjectList) {
				$selectSubjectnHTML .= '<optgroup label="' . $subjectCourseField . '">';
					foreach($selectSubjectList as $subjectListField => $subjectListVal) {
						$selectSubjectnHTML .= '<optgroup label="' . $subjectListField . '">';
							foreach($subjectListVal as $subjectVal) {
								$subjectHTML = ( $_GET['txtsubject'] == $subjectVal['subj_idPK'] ) ? 'selected' : '';
								$selectSubjectnHTML .= '<option value="' . $subjectVal['subj_idPK'] . '" ' . $subjectHTML . '>' . $subjectVal['subj_desc'] . ' (' . $subjectVal['subj_code'] . ')' . '</option>';
							}
						$selectSubjectnHTML .= '</optgroup">';
					}
				$selectSubjectnHTML .= '</optgroup">';
			}
		}
	$selectSubjectnHTML .= '</select>';
	
	$TEMP->set_var(array('search' 			=> $search,
						 'pagination'		=> $pagination,
						 'results'			=> "<strong>" . $listCountStudentInformation . "</strong> results",
						 'urlPage'			=> $urlPage,
						 'txtstudno'		=> $_GET['txtstudno'],
						 'txtfirst'			=> $_GET['txtfirst'],
						 'txtlast'			=> $_GET['txtlast'],
						 'semesterselect'	=> $selectSemesterHTML,
						 'sectionselect'	=> $selectSectionHTML,
						 'subjectsselect'	=> $selectSubjectnHTML,
						 'header_table'		=> $headerTable,
						 'print_button'		=> $printButton
						));
?>